package com.producteev4j.model.json.dashboard;

import com.producteev4j.model.json.user.UserWrapperImpl;
import com.producteev4j.model.request.ProducteevDateUtil;
import com.producteev4j.model.response.BaseResponse;
import com.producteev4j.model.response.DashBoard;
import org.codehaus.jackson.annotate.JsonAutoDetect;
import org.codehaus.jackson.annotate.JsonProperty;

import java.text.ParseException;
import java.util.Date;
import java.util.List;

/**
 * Created by IntelliJ IDEA.
 * User: jcarrey
 * Date: 18/05/11
 * Time: 9:47
 * To change this template use File | Settings | File Templates.
 */
@JsonAutoDetect(getterVisibility = JsonAutoDetect.Visibility.ANY)
public class DashBoardImpl extends BaseResponse implements DashBoard {

    @JsonProperty("id_dashboard")
    private long idDashboard;

    @JsonProperty("title")
    private String title;

    @JsonProperty("id_creator")
    private long idCreator;


    @JsonProperty("write_ok")
    public void setWriteOkAsInt(int writeOkAsInt) {
        writeOk = writeOkAsInt != 0;
    }

    private boolean writeOk;

    @JsonProperty("time_lastchange")
    public void setLastChangeAsString(String lastChangeAsString) {
        try {
            lastChange = ProducteevDateUtil.parseDateRFC(lastChangeAsString);
        } catch (ParseException e) {
            lastChange = null;
        }
    }

    private Date lastChange;

    @JsonProperty("status")
    private int status;

    @JsonProperty("deleted")
    public void setDeletedAsInt(int deletedAsInt) {
        deleted = deletedAsInt != 0;
    }

    private boolean deleted;

    @JsonProperty("smart_labels")
    public void setSmartLabelsAsInt(int smartLabelsAsInt) {
        smartLabels = smartLabelsAsInt != 0;
    }

    private boolean smartLabels;

    @JsonProperty("needs_upgrade")
    public void setNeedsUpgradeAsInt(int needsUpgradeAsInt) {
        needsUpgrade = needsUpgradeAsInt != 0;
    }

    private boolean needsUpgrade;

    @JsonProperty("accesslist")
    private List<UserWrapperImpl> accessList;

    public long getIdDashboard() {
        return idDashboard;
    }

    public void setIdDashboard(long idDashboard) {
        this.idDashboard = idDashboard;
    }

    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public long getIdCreator() {
        return idCreator;
    }

    public void setIdCreator(long idCreator) {
        this.idCreator = idCreator;
    }

    public boolean isWriteOk() {
        return writeOk;
    }

    public void setWriteOk(boolean writeOk) {
        this.writeOk = writeOk;
    }

    public Date getLastChange() {
        return lastChange;
    }

    public void setLastChange(Date lastChange) {
        this.lastChange = lastChange;
    }

    public int getStatus() {
        return status;
    }

    public void setStatus(int status) {
        this.status = status;
    }

    public boolean isDeleted() {
        return deleted;
    }

    public boolean isSmartLabels() {
        return smartLabels;
    }


    public boolean isNeedsUpgrade() {
        return needsUpgrade;
    }

    public List<UserWrapperImpl> getAccessList() {
        return accessList;
    }

    public void setAccessList(List<UserWrapperImpl> accessList) {
        this.accessList = accessList;
    }
}
